<include file="Public/header" />
<include file="Public/menu" />

<!-- 内容页 -->
<div class="content-wrapper">
    <!-- 面包屑 -->
    <section class="content-header">
        <h1>
            售后
            <small>退款退货列表</small>
        </h1>
        <ol class="breadcrumb">
            <li><a href="{:U('index/index')}"><i class="fa fa-dashboard"></i> 首页</a></li>
            <li><a href="{:U('Refund/index')}"><i class="fa fa-dashboard"></i> 售后</a></li>
            <li class="active">退款退货列表</li>
        </ol>
    </section>

    <!-- 内容 -->
    <section class="content">
        <!--1申请退货,2进行退货,3,物流信息,4确认退货,5退货失败-->
        <div class="row"><div class="col-md-12"><div class="nav-tabs-custom">
            <ul class="nav nav-tabs">
                <li <if condition="I('get.view') eq 1 or $view eq 1" >class="active"</if> ><a href="{:U(Refund/index,array('view'=>1))}">待处理</a></li>
                <li <if condition="I('get.view') eq 2 or $view eq 2" >class="active"</if> ><a href="{:U(Refund/index,array('view'=>2))}">已处理</a></li>
                <li <if condition="I('get.view') eq 9 or $view eq 9" >class="active"</if> ><a href="{:U(Refund/index,array('view'=>9))}">全部</a></li>
                <li class="pull-right header"></li>
            </ul>
            <div class="tab-content">
                <div class="box-header">
                    <h3 class="box-title"></h3>

                    <div class="form-inline pull-right">
                        <form action="{:U('Refund/index',array('view'=>$view,'order_field'=>'id','order'=>$order), '')}" method="get" pjax-container="">
                            <fieldset>
                                <select class="form-control" name="search_field" style="height: 30px; font-size: 12px;">
                                    <option value="order_id" <if condition="$search_field eq 'order_id'">selected="selected"</if>>订单号</option>
                                    <option value="ship_name" <if condition="$search_field eq 'ship_name'">selected="selected"</if>>收货人姓名</option>
                                    <option value="ship_mobile" <if condition="$search_field eq 'ship_mobile'">selected="selected"</if>>收货人电话</option>
                                </select>
                                <div class="input-group input-group-sm">
                                    <div class="input-group input-group-sm">
                                        <input type="text" class="form-control" placeholder="" name="search" value="{$search}">
                                    </div>
                                </div>
                                <div class="input-group input-group-sm">
                                    <div class="input-group-btn">
                                        <button type="submit" class="btn btn-primary"><i class="fa fa-search"></i></button>
                                    </div>
                                </div>
                            </fieldset>
                        </form>
                    </div>
                </div>

                <div class="tab-pane active" id="tab_0">
                    <div class="box">

                        <!-- /.box-header -->
                        <div class="box-body table-responsive no-padding">
                            <table class="table table-hover" style="width: 100%;">
                                <tbody><tr>
                                    <th><input type="checkbox" class="grid-select-all"></th>
                                    <th>ID<a class="fa fa-fw fa-sort" href="{:U('Refund/index',array('view'=>$view,'p'=>$p,'order_field'=>'id','order'=>$order), '')}"></a></th>
                                    <th>订单编号</th>
                                    <th>下单时间</th>
                                    <th>退单时间</th>
                                    <th>门店<a class="fa fa-fw fa-sort" href="{:U('Refund/index',array('view'=>$view,'p'=>$p,'order_field'=>'local_id','order'=>$order), '')}"></a></th>
                                    <th>收货人</th>
                                    <th>收货人电话</th>
                                    <th>退款金额</th>
                                    <th>审核金额</th>
                                    <th>财务确认金额</th>
                                    <th>状态</th>
                                    <th>类型<a class="fa fa-fw fa-sort" href="{:U('Refund/index',array('view'=>$view,'p'=>$p,'order_field'=>'type','order'=>$order), '')}"></a></th>
                                    <th>操作</th>
                                </tr>
                                <volist name="list" id="item">
                                    <tr>
                                        <td><input type="checkbox" class="grid-item" data-id="{$item.id}"></td>
                                        <td>{$item.id}</td>
                                        <td>{$item.order_id}</td>
                                        <td>{$item.createtime|date="Y-m-d H:i:s",###}</td>
                                        <td>{$item.start_time|date="Y-m-d H:i:s",###}</td>
                                        <td>{$item.local_name}</td>
                                        <td>{$item.ship_name}</td>
                                        <td>{$item.ship_mobile}</td>
                                        <td>{$item.price}</td>
                                        <td>{$item.store_money}</td>
                                        <td>{$item.price_detail}</td>
                                        <td>{$item.state}</td>
                                        <td><if condition="$item['type'] eq 1"><span class="label label-info">售前退款</span>
                                            <elseif condition="$item['type'] eq 2" /><span class="label label-warning">售后退款</span>
                                            <elseif condition="$item['type'] eq 3" /><span class="label label-danger">售后退货退款</span>
                                        </if>
                                        </td>
                                        <td>
                                            <a data-id="{$item.id}" data-oid="{$item.order_id}" class="btn btn-sm btn-success _detail">查看</a>
                                        </td>
                                    </tr>
                                </volist>
                                </tbody></table>
                        </div>
                        <div class="box-footer clearfix">
                            <input type="checkbox" class="grid-select-all">&nbsp;&nbsp;&nbsp;
                            <!--<a class="btn btn-sm btn-danger batch-delete">批量删除</a>-->

                            <a class="btn btn-sm btn-primary grid-refresh"><i class="fa fa-refresh"></i></a>

                            {$page}

                        </div>
                        <!-- /.box-body -->
                    </div>

                    <!-- 模态框（Modal） -->
                    <div class="modal fade" id="myModalDetail" tabindex="-1" role="dialog"
                         aria-labelledby="myModalLabe" aria-hidden="true">
                        <div class="modal-dialog modal-lg" style="width: 1400px;">
                            <div class="modal-content">
                                <div class="modal-header">
                                    <button type="button" class="close" data-dismiss="modal"
                                            aria-hidden="true">×
                                    </button>
                                    <h4 class="modal-title" id="myModalLabel">
                                        订单详情
                                    </h4>
                                </div>
                                <div class="modal-body" id="tuiluoinfo">
                                    ...
                                </div>
                                <div class="modal-footer">
                                    <button type="button" class="btn btn-default" data-dismiss="modal">
                                        关闭
                                    </button>
                                </div>
                            </div><!-- /.modal-content -->
                        </div><!-- /.modal-dialog -->
                    </div><!-- /.modal -->

                    <!-- 模态框（Modal） -->
                    <!--<div class="modal fade" id="myModallogs" tabindex="-1" role="dialog"
                         aria-labelledby="myModalLabel,l" aria-hidden="true">
                        <div class="modal-dialog">
                            <div class="modal-content">
                                <div class="modal-header">
                                    <button type="button" class="close" data-dismiss="modal"
                                            aria-hidden="true">×
                                    </button>
                                    <h4 class="modal-title" id="myModalLabel2">
                                        订单状态变更日志11
                                    </h4>
                                </div>
                                <div class="modal-body">
                                    暂无记录
                                </div>
                                <div class="modal-footer">
                                    <button type="button" class="btn btn-default" data-dismiss="modal">
                                        关闭
                                    </button>
                                </div>
                            </div>&lt;!&ndash; /.modal-content &ndash;&gt;
                        </div>&lt;!&ndash; /.modal-dialog &ndash;&gt;
                    </div>--><!-- /.modal -->

                    <!--<div class="modal fade" id="myModal" tabindex="-1" role="dialog"
                         aria-labelledby="myModalLabel" aria-hidden="true">
                        <div class="modal-dialog">
                            <div class="modal-content">
                                <div class="modal-header">
                                    <button type="button" class="close" data-dismiss="modal"
                                            aria-hidden="true">×
                                    </button>
                                    <h4 class="modal-title" id="myModalLabel">
                                        订单状态变更
                                    </h4>
                                </div>
                                <div class="modal-body">
                                    <form action="" role="form" id="purchase-mark">
                                        <div class="form-group">
                                            <input type="hidden" name="purc_id" value="">
                                            <input type="hidden" name="status" value="">
                                            <input type="hidden" name="status" value="">
                                            <label for="exampleInputEmailbz">备注</label>
                                            <textarea class="form-control" rows="2" id="exampleInputEmailbz" placeholder="添加备注" name="desc"></textarea>
                                        </div>
                                    </form>
                                </div>
                                <div class="modal-footer">
                                    <button type="button" class="btn btn-default" data-dismiss="modal">
                                        关闭
                                    </button>
                                    <button type="button" class="btn btn-primary  mark-submit">
                                        提交
                                    </button>
                                </div>
                            </div>&lt;!&ndash; /.modal-content &ndash;&gt;
                        </div>&lt;!&ndash; /.modal-dialog &ndash;&gt;
                    </div>--><!-- /.modal -->

                </div>

                <div class="tab-pane" id="tab_{$k}">
                    <div class="box">
                        <div class="box-body table-responsive no-padding">
                            {$table}
                        </div>
                    </div>
                </div>


            </div>
        </div></div></div>

    </section>
</div>
<!-- 底部 -->
<include file="Public/common_footer" />

<script data-exec-on-popstate>
    $(function () {
        $('.mark-submit').click(function () {

            var purc_id = $('#purchase-mark').find('input[name=purc_id]').val();
            var status = $('#purchase-mark').find('input[name=status]').val();
            var before = $('#purchase-mark').find('input[name=before]').val();
            var desc = $('#purchase-mark').find('textarea[name=desc]').val();
            if (purc_id != '' && status != '' && desc != '') {
                $.ajax({
                    type: "POST",
                    url: "{:U('purchase/change_status')}",
                    data: {purc_id:purc_id, status:status, desc:desc, before:before},
                    success: function(msg){
                        if (msg.status) {
                            alert(msg.message);
                        } else {
                            alert(msg.message)
                        }
                        window.location.reload();
                    },
                    error: function (msg) {
                        alert(msg.message);
                    }
                });
            } else {
                alert('缺少参数');
            }
        });

        $('.__confirm').click(function () {
            $('#myModal').modal('show');
            var purc_id = $(this).attr('data-id');
            var before = $(this).attr('before');
            var status = $(this).attr('status');
            $('#purchase-mark').find('input[name=purc_id]').val(purc_id);
            $('#purchase-mark').find('input[name=before]').val(before);
            $('#purchase-mark').find('input[name=status]').val(status);
        });

        $('._logs').click(function () {
            $('#myModallogs').modal('show');
            var purc_id = $(this).attr('data-id');
            if (purc_id != '') {
                $.ajax({
                    type: "get",
                    url: "{:U('purchase/get_purchase_logs')}",
                    data: {purc_id:purc_id},
                    success: function(msg){
                        $('#myModallogs').modal('show');
                        var html='';
                        if (msg) {
                            for (var i=0; i<msg.length; i++) {
                                html += '<p class="message"><a class="name"> <small class="text-muted pull-right"><i class="fa fa-clock-o"></i>';
                                html += msg[i].create_time + '</small>';
                                html += msg[i].manage_name + '</a>&nbsp;&nbsp;&nbsp;&nbsp;将状态变更为：<a>';
                                html += msg[i].later_status+'</a><br><label class="control-label">备注内容：</label>';
                                html += msg[i].desc + '</p>';
                            }
                        }
                        $('#myModallogs').find('.modal-body').html(html);
                    },
                    error: function (msg) {
                        alert(msg.message);
                    }
                });
            } else {
                alert('缺少参数');
            }
        });

        $('._detail').click(function () {
            //$('#myModalDetail').modal('show');
            var id = $(this).attr('data-id');
            var oid = $(this).attr('data-oid');

            if (id != '') {
                $.ajax({
                    type: "get",
                    url: "{:U('Refund/getOrderDetail')}",
                    data: {id:id,order_id:oid},
                    success: function(msg){
                        var html='';
                        if (msg.status) {
                            html = msg.data;
                        }
                        $('#tuiluoinfo').html(html);
                        $('#myModalDetail').modal('show');
                    },
                    error: function (msg) {
                        alert(msg.message);
                    }
                });
            } else {
                alert('缺少参数');
            }
        });
    })
</script>